<template>
  <div id="app-container">
    <!-- 显示流步骤 -->
    <el-steps :active="3" align-center process-status="wait" style="margin-bottom: 40px">
      <el-step title="填写课程基本信息"></el-step>
      <el-step title="创建课程大纲"></el-step>
      <el-step title="发布课程"></el-step>
    </el-steps>
  <div class="app-container">
    <div class="ccInfo">
      <img :src="publishCourse.cover"  alt="课程封面"/>
      <div class="main">
        <h2>{{ publishCourse.title }}</h2>
        <p class="gray">
          <span>共{{ publishCourse.lessonNum }}课时</span>
        </p>
        <p>
          <span
          >所属分类：{{ publishCourse.subjectLevelOne }} —
            {{ publishCourse.subjectLevelTwo }}</span
          >
        </p>
        <p>课程讲师：{{ publishCourse.teacherName }}</p>
        <h3 class="red">￥{{ publishCourse.price }}</h3>
      </div>
    </div>


    <el-form>
      <el-button @click="back()" style="margin: 0 6rem;" type="primary">回到上一步</el-button>
      <el-button @click="publish()" type="primary">保存并发布</el-button>

    </el-form>
  </div>
  </div>
</template>

<script>
  import course from '@/api/edu/course'

  export default {
    name: 'publish',
    data() {
      return {
        publishCourse: {
        }
      }
    },
    methods: {
      back() {
        this.$router.push('/course/save/chapter/1')
      },

      // 根据课程 id ，查询课程相关发布信息
      getPublishCourseById(id) {
        course.getPublishCourseInfo(id).then(res => {
          this.publishCourse = res.data.publishCourseInfo
        })
      },
      publish(){
          course.publish(this.publishCourse.id).then(res=>{
            this.$message.success(res.message)
            this.$router.push("/course/list")
          })
      }
    },
    created() {
      this.$store.dispatch('app/saveActive', 3)

      // 判断是否存在课程 id，有就进行查询课程相关信息
      if (this.$route.params && this.$route.params.id) {
        this.getPublishCourseById(this.$route.params.id)
      }

    }
  }
</script>

<style scoped>
  .app-container{
    width: 600px;
    margin: 0 auto;
  }

  .ccInfo {
    background: #f5f5f5;
    padding: 20px;
    overflow: hidden;
    border: 1px dashed #ddd;
    margin-bottom: 40px;
    position: relative;
  }
  .ccInfo img {
    background: #d6d6d6;
    width: 300px;
    display: block;
    float: left;
    border: none;
  }
  .ccInfo .main {
    margin-left: 320px;
  }

  .ccInfo .main h2 {
    font-size: 28px;
    margin-bottom: 30px;
    line-height: 1;
    font-weight: normal;
  }
  .ccInfo .main p {
    margin-bottom: 10px;
    word-wrap: break-word;
    line-height: 24px;
    max-height: 48px;
    overflow: hidden;
  }

  .ccInfo .main p {
    margin-bottom: 10px;
    word-wrap: break-word;
    line-height: 24px;
    max-height: 48px;
    overflow: hidden;
  }
  .ccInfo .main h3 {
    left: 340px;
    bottom: 0;
    line-height: 1;
    font-size: 28px;
    color: #d32f24;
    font-weight: normal;
    position: absolute;
  }
</style>
